# -*- coding: utf-8 -*-
# @Time : 2021/9/9 15:09
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : test_shangji.py
# @Project : crm
'''验证添加商机功能'''

from time import sleep
from selenium.webdriver.common.by import By
from selenium import webdriver
from utils.get_cookie import cookie
from utils import util
from selenium.webdriver.support.select import Select
#定位器
fzr_locator=(By.CSS_SELECTOR,"#owner_name")
fzr_xz_locator=(By.XPATH,"//*[@id='d_content']/tr[1]/td[1]/input")
fzr_queren_locator=(By.XPATH,'/html/body/div[12]/div[3]/div/button[1]/span')
kehu_locator=(By.CSS_SELECTOR,'#customer_name')
kehu_xz_locator=(By.XPATH,'//*[@id="datas"]/tr[1]/td[1]/input')
kehu_queren_locator=(By.XPATH,"/html/body/div[10]/div[3]/div/button[1]/span")
jine_locator=(By.CSS_SELECTOR,"#total_price")
shangji_name_locator=(By.CSS_SELECTOR,'#name')
lianxiren_locator=(By.CSS_SELECTOR,'#contacts_name')
lianxiren_xz_locator=(By.XPATH,'//*[@id="data2"]/tr[1]/td[1]/input')
lianxiren_queren_locator=(By.XPATH,'/html/body/div[11]/div[3]/div/button[1]/span')
shengfen_locator=(By.NAME,"contract_address['state']")
shi_locator=(By.NAME,"contract_address['city']")
qu_locator=(By.NAME,"contract_address['area']")
jie_locator=(By.CSS_SELECTOR,'input[placeholder="街道信息"]')
shangjileixing_locator=(By.CSS_SELECTOR,"#type")
zhuangtai_locator=(By.CSS_SELECTOR,'#status_id')
shangjilaiyuan_locator=(By.CSS_SELECTOR,"#origin")
yingdanlv_locator=(By.CSS_SELECTOR,"#gain_rate")
yuqijiage_locator=(By.CSS_SELECTOR,'#estimate_price')
xiacilianxi_time_locator=(By.CSS_SELECTOR,'#nextstep_time')
xiacilianxi_leirong_locator=(By.CSS_SELECTOR,'#nextstep')
beizhu_locator=(By.CSS_SELECTOR,'#description')
baicheng_locator=(By.CSS_SELECTOR,'input[value="保存"')


#前提条件

cookie=cookie(util.HOST,util.name,util.password)
driver=webdriver.Chrome()
driver.add_cookie(cookie)
driver.get('http://192.168.1.155/crm/index.php?m=business&a=add')

#测试用例步骤
try:
    #选择负责人
    driver.find_element(*fzr_locator).click()
    driver.find_element(*fzr_xz_locator).click()
    driver.find_element(*fzr_queren_locator).click()


    #选择客户
    driver.find_element(*kehu_locator).click()
    driver.find_element(*kehu_xz_locator).click()
    driver.find_element(*kehu_queren_locator).click()


    #输入商机金额
    driver.find_element(*jine_locator).send_keys("10000")
    #输入商机名
    driver.find_element(*shangji_name_locator).send_keys('风格和')
    #选择联系人
    driver.find_element(*lianxiren_locator).click()
    driver.find_element(*lianxiren_xz_locator).click()
    driver.find_element(*lianxiren_queren_locator).click()
    #选择合同签定地址
    '''选择省'''
    shengfen_element=driver.find_element(*shengfen_locator)
    select=Select(shengfen_element)
    select.select_by_index(1)
    '''选择市'''
    shi_element=driver.find_element(*shi_locator)
    select=Select(shi_element)
    select.select_by_index(1)
    '''选择区'''
    qu_element = driver.find_element(*qu_locator)
    select = Select(qu_element)
    select.select_by_index(1)
    '''输入街道'''
    jie_element=driver.find_element(*jie_locator)
    jie_element.click()
    jie_element.send_keys('街道')
    #选择商机类型
    shangjileixing_element = driver.find_element(*shangjileixing_locator)
    select = Select(shangjileixing_element)
    select.select_by_index(1)
    #选择状态
    zhuangtai_element=driver.find_element(*zhuangtai_locator)
    select = Select(zhuangtai_element)
    select.select_by_index(1)
    #选择商业来源
    shangjilaiyuan_element = driver.find_element(*shangjilaiyuan_locator)
    select = Select(shangjilaiyuan_element)
    select.select_by_index(1)
    #输入赢单率
    driver.find_element(*yingdanlv_locator).send_keys("75.00")
    #输入预期价格
    driver.find_element(*yuqijiage_locator).send_keys("1212")
    #输入下次联系时间
    driver.find_element(*xiacilianxi_time_locator).send_keys('2021-09-28')
    #输入下次联系内容
    driver.find_element(*xiacilianxi_leirong_locator).send_keys("初步沟通")
    #输入备注
    driver.find_element(*beizhu_locator).send_keys('商务部门对接')
    #点击保存
    # driver.find_element(*baicheng_locator).click()




except Exception as e:
    raise e
finally:
    sleep(5)
    driver.quit()